#include "stringtokentest.h"
#include "stringtokenizer.h"

#include <cppunit/config/SourcePrefix.h>

using namespace MCCommon;

CPPUNIT_TEST_SUITE_REGISTRATION( TestStringToken );

TestStringToken::TestStringToken()
{
}

TestStringToken::~TestStringToken()
{
}

void
TestStringToken::Test()
{
    std::string str;
    StringTokenizer tokenizer;
    std::vector< std::string > arrStr;
    
    {
        str = "aaa";
        arrStr.clear();
        StringToArray( str, arrStr );

        CPPUNIT_ASSERT( arrStr.size() == 1 );
        CPPUNIT_ASSERT( arrStr[0].compare( "aaa" ) == 0 );        
    }

    {
        str = "aaa;";
        arrStr.clear();
        StringToArray( str, arrStr );

        CPPUNIT_ASSERT( arrStr.size() == 1 );
        CPPUNIT_ASSERT( arrStr[0].compare( "aaa" ) == 0 );        
    }

    {
        str = "aaa;bbb"; 
        arrStr.clear();       
        StringToArray( str, arrStr );

        CPPUNIT_ASSERT( arrStr.size() == 2);
        CPPUNIT_ASSERT( arrStr[0].compare("aaa") == 0 );
        CPPUNIT_ASSERT( arrStr[1].compare("bbb") == 0 );
    }

    {
        str = "aaa;bbb;";
        arrStr.clear();   
        StringToArray( str, arrStr );
        
        CPPUNIT_ASSERT( arrStr.size() == 2);
        CPPUNIT_ASSERT( arrStr[0].compare("aaa") == 0 );
        CPPUNIT_ASSERT( arrStr[1].compare("bbb") == 0 );
    }

    {
        str = " aaa?;bbb?;";
        arrStr.clear();   
        StringToArray( str, arrStr, "?;" );

        CPPUNIT_ASSERT( arrStr.size() == 2);
        CPPUNIT_ASSERT( arrStr[0].compare(" aaa") == 0 );
        CPPUNIT_ASSERT( arrStr[1].compare("bbb") == 0 );
    }

    {
        arrStr.clear();
        arrStr.push_back( "aaa" );
        arrStr.push_back( " bbb" );
            
        ArrayToString( arrStr, str, "?");
        CPPUNIT_ASSERT( str.compare("aaa? bbb?") == 0 );
    }
}